# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.spark_submit import SparkSubmitOperator
from jms.dwd.tms.dwd_tmsnew_shipment_stop_union_base_dt import jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt
from jms.dwd.tms.dwd_tmsnew_shipment_union_base_dt import jms_dwd__dwd_tmsnew_shipment_union_base_dt
from jms.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms.dwd.tab.dwd_tab_barscan_loading_base_dt import jms_dwd__dwd_tab_barscan_loading_base_dt
from jms.dwd.tab.dwd_tab_barscan_centerarrival_base_dt import jms_dwd__dwd_tab_barscan_centerarrival_base_dt
from jms.dwd.dwd_warhouse.dwd_wide_unsign_summary_waybill_dt import jms_dwd__dwd_wide_unsign_summary_waybill_dt
from jms.dim.dim_lmdm_sys_network_expand import jms_dim__dim_lmdm_sys_network_expand
from jms.dwd.tab.dwd_tab_barscan_centersend_base_dt import jms_dwd__dwd_tab_barscan_centersend_base_dt
jms_dm__dm_center_hour_count_summary_dt_bak = SparkSubmitOperator(
    task_id='jms_dm__dm_center_hour_count_summary_dt_bak',
    email=['shenjiaming@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_center_hour_count_summary_dt_{{ execution_date | date_add(1) | cst_ds }}',
    pool_slots=5,
    pool='unlimited_pool',
    driver_memory='12G',
    driver_cores=4,
    executor_memory='12G',
    executor_cores=4,
    num_executors=40,
    yarn_queue='pro',
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 80,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 600,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '12G',  # 堆外内存
          'spark.default.parallelism': 680,
          'spark.sql.shuffle.partitions': 680,
          'spark.core.connection.ack.wait.timeout': '600',
          'spark.shuffle.io.maxRetries': '6',
          'spark.driver.maxResultSize': '36G'
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': '5000',
              'hive.exec.max.dynamic.partitions': '30000',
              'hive.optimize.bucketmapjoin': 'true',
              'hive.optimize.bucketmapjoin.sortedmerge': 'true',
              'hive.input.format': 'org.apache.hadoop.hive.ql.io.BucketizedHiveInputFormat',
              'hive.auto.convert.sortmerge.join': 'true',
              'hive.auto.convert.sortmerge.join.noconditionaltask': 'true'
              },

    jars='hdfs:///scheduler/jms/spark/sjm/ExportCenterHourCount/common-1.0-SNAPSHOT.jar',  # 依赖 jar 包
    java_class='com.yunlu.bigdata.jobs.export.ExportCenterHourCountReport',  # spark 主类
    application='hdfs:///scheduler/jms/spark/sjm/ExportCenterHourCount/original-jobs-1.0-SNAPSHOT.jar',
    # spark jar 包
    application_args=['{{ execution_date | cst_ds }}'],
    execution_timeout=timedelta(minutes=30)
)
jms_dm__dm_center_hour_count_summary_dt_bak << [
    jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt,
    jms_dwd__dwd_tmsnew_shipment_union_base_dt,
    jms_dim__dim_network_whole_massage,
    jms_dwd__dwd_tab_barscan_loading_base_dt,
    jms_dwd__dwd_tab_barscan_centerarrival_base_dt,
    jms_dim__dim_lmdm_sys_network_expand,
    jms_dwd__dwd_tab_barscan_centersend_base_dt,
    jms_dwd__dwd_wide_unsign_summary_waybill_dt
]